/*
 * @Descripttion: 淘宝订单系统
 * @version: 2.0
 * @Author: kiming<shufan209@qq.com>
 * @Date: 2021-12-25 22:03:10
 * @LastEditors: kiming<shufan209@qq.com>
 * @LastEditTime: 2022-06-04 15:58:40
 */
import $ from "jquery";
import _Base64 from "js-base64"
import config from '@/config';


const Base64 = _Base64.Base64;

export const apiMap = (url, params) => {
    params.output = "jsonp"
    return ajax(url, params, "jsonp").then(res => {
        return res;
    })
}

export const apiFont = (params) => {
    let url = config.dbHost + 'service/listProdByParam/' + buildurl(params);
    return ajax(url).then(res => {
        return res;
    })
}



 


export const apiMusic = (params) => {
    let url = config.dbHost + 'music/song/hash/' + encodeStr(JSON.stringify(params), "123456");
    return ajax(url).then(res => {
        return res;
    })
}

export const ajax = (url, params, dataType = "json") => {
    let cross = !(url.indexOf(window.location.host) != -1);
    return new Promise((resolve, reject) => {
        $.ajax({
            url: url,
            type: "GET",
            cache: true,
            dataType: dataType,
            data: params,
            crossDomain: cross,
            success: function(res) {
                resolve(res)
            },
            error: function(error) {
                reject(error)
            }
        })
    })
}

export const encodeStr = (string, key) => {
    let code = '';
    string = Base64.encode(string);
    let len = key.length;
    let i;
    let k;
    for (i = 0; i < string.length; i++) {
        k = i % len;
        code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k));
    };
    return Base64.encode(code).replace(/[\/]/g, "_")
}
export const getQueryStr = (name) => {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}
export const buildurl = (param, type = "key") => {
    let dataArr = [];
    for (var name in param) {
        if (param[name]) {
            dataArr.push(name + (type == "key" ? '/' : "=") + param[name])
        }
    };
    return dataArr.join(type == "key" ? '/' : "&")
}

export const batchdelqiniu = () => {
  return ajax("http://api.admin.com/api/test").then(res => {
      return res;
  })
}

export const getSysWords = () => {
  return ajax("http://s1-cdn.wedlaa.com/zitie/renjiaoFonts.json").then(res => {
      return res;
  })
}